package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
	"log"
	"shang/conmon"
	"shang/models"
)

type UpController struct {
	beego.Controller
}

func (u *UpController) Password() {
	username := u.GetString("username")
	mobile := u.GetString("mobile")
	code := u.GetString("code")
	password := u.GetString("password")
	log.Println(code, mobile)
	//getCode := models.Redis.Get("code" + mobile).Val()
	//if code != getCode {
	//	u.Data["json"] = map[string]interface{}{
	//		"code": 400,
	//		"msg":  "验证码错误",
	//	}
	//	u.ServeJSON()
	//}
	user, _ := models.GetUserInfo(models.User12{
		Username: username,
	})
	if user.Id == 0 {
		u.Data["json"] = map[string]interface{}{
			"code": 400,
			"msg":  "账号不存在",
		}
		u.ServeJSON()
	}
	m := conmon.Md5(password)
	user.Password = m
	_, err := models.SaveUser(user)
	if err != nil {
		u.Data["json"] = map[string]interface{}{
			"code": 400,
			"msg":  "修改失败",
		}
		u.ServeJSON()
	}
	u.Data["json"] = map[string]interface{}{
		"code": 200,
		"msg":  "修改成功",
	}
	u.ServeJSON()
}
